/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Przewoźnik_Kontroler.java
 *
 */

package adbus;

import adbus.models.*;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
/**
 *klasa odpowiedzialna z wyswietlanie okna dodania przewoznika
 * i obsluge zdarzen z nim zwiazanych
 * @author Kasia
 */
public class Przewoźnik_Kontroler extends javax.swing.JDialog {

    private Przewoznik carrier = new Przewoznik();
    private PrzewoznikTable carriersTable = null;
    /** Creates new form Przewoźnik_Kontroler */
    public Przewoźnik_Kontroler(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
/**dwuargumentowy konstruktor klasy Przewoznik_Kontener*/
    public Przewoźnik_Kontroler(JFrame mainFrame, PrzewoznikTable cTable) {
        super(mainFrame,true);
        initComponents();
        carriersTable = cTable;
    }
/**trzyargumentowy konstruktor klasy Przewoznik_Kontener*/
    public Przewoźnik_Kontroler(JFrame mainFrame, PrzewoznikTable cTable, Przewoznik przewoznik) {
        super(mainFrame,true);
        carrier = przewoznik;
        carriersTable = cTable;
        initComponents();

    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        carrierName = new javax.swing.JTextField();
        carrierCity = new javax.swing.JTextField();
        carrierPhone = new javax.swing.JTextField();
        carrierAddress = new javax.swing.JTextField();
        carrierCPName = new javax.swing.JTextField();
        carrierCPPhone = new javax.swing.JTextField();
        carrierCPMail = new javax.swing.JTextField();
        carrierCPSurname = new javax.swing.JTextField();
        carrierInformation = new javax.swing.JTextField();
        carrierMail = new javax.swing.JTextField();
        cancelButton1 = new javax.swing.JButton();
        okButton = new javax.swing.JButton();
        carrierNameLabel = new javax.swing.JLabel();
        carrierCityLabel = new javax.swing.JLabel();
        carrierAddressLabel = new javax.swing.JLabel();
        carrierPhoneLabel = new javax.swing.JLabel();
        carrierMailLabel = new javax.swing.JLabel();
        carrierInformationLabel = new javax.swing.JLabel();
        carrierCPNameLabel = new javax.swing.JLabel();
        carrierCPSurnameLabel = new javax.swing.JLabel();
        carrierCPPhoneLabel = new javax.swing.JLabel();
        carrierCPMailLabel = new javax.swing.JLabel();
        carrierContactPerson = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        carrierName.setText(carrier.nazwa);
        carrierName.setName("carrierName"); // NOI18N

        carrierCity.setText(carrier.miasto);
        carrierCity.setName("carrierCity"); // NOI18N

        carrierPhone.setText(carrier.telefon);
        carrierPhone.setName("carrierPhone"); // NOI18N

        carrierAddress.setText(carrier.adres);
        carrierAddress.setName("carrierAddress"); // NOI18N

        carrierCPName.setText(carrier.ok_imie);
        carrierCPName.setName("carrierCPName"); // NOI18N

        carrierCPPhone.setText(carrier.ok_telefon);
        carrierCPPhone.setName("carrierCPPhone"); // NOI18N

        carrierCPMail.setText(carrier.ok_mail);
        carrierCPMail.setName("carrierCPMail"); // NOI18N

        carrierCPSurname.setText(carrier.ok_nazwisko);
        carrierCPSurname.setName("carrierCPSurname"); // NOI18N

        carrierInformation.setText(carrier.uwagi);
        carrierInformation.setName("carrierInformation"); // NOI18N

        carrierMail.setText(carrier.mail);
        carrierMail.setName("carrierMail"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(adbus.AdBusApp.class).getContext().getResourceMap(Przewoźnik_Kontroler.class);
        cancelButton1.setText(resourceMap.getString("cancelButton1.text")); // NOI18N
        cancelButton1.setName("cancelButton1"); // NOI18N
        cancelButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButton1ActionPerformed(evt);
            }
        });

        okButton.setText(resourceMap.getString("okButton.text")); // NOI18N
        okButton.setName("okButton"); // NOI18N
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        carrierNameLabel.setText(resourceMap.getString("carrierNameLabel.text")); // NOI18N
        carrierNameLabel.setName("carrierNameLabel"); // NOI18N

        carrierCityLabel.setText(resourceMap.getString("carrierCityLabel.text")); // NOI18N
        carrierCityLabel.setName("carrierCityLabel"); // NOI18N

        carrierAddressLabel.setText(resourceMap.getString("carrierAddressLabel.text")); // NOI18N
        carrierAddressLabel.setName("carrierAddressLabel"); // NOI18N

        carrierPhoneLabel.setText(resourceMap.getString("carrierPhoneLabel.text")); // NOI18N
        carrierPhoneLabel.setName("carrierPhoneLabel"); // NOI18N

        carrierMailLabel.setText(resourceMap.getString("carrierMailLabel.text")); // NOI18N
        carrierMailLabel.setName("carrierMailLabel"); // NOI18N

        carrierInformationLabel.setText(resourceMap.getString("carrierInformationLabel.text")); // NOI18N
        carrierInformationLabel.setName("carrierInformationLabel"); // NOI18N

        carrierCPNameLabel.setText(resourceMap.getString("carrierCPNameLabel.text")); // NOI18N
        carrierCPNameLabel.setName("carrierCPNameLabel"); // NOI18N

        carrierCPSurnameLabel.setText(resourceMap.getString("carrierCPSurnameLabel.text")); // NOI18N
        carrierCPSurnameLabel.setName("carrierCPSurnameLabel"); // NOI18N

        carrierCPPhoneLabel.setText(resourceMap.getString("carrierCPPhoneLabel.text")); // NOI18N
        carrierCPPhoneLabel.setName("carrierCPPhoneLabel"); // NOI18N

        carrierCPMailLabel.setText(resourceMap.getString("carrierCPMailLabel.text")); // NOI18N
        carrierCPMailLabel.setName("carrierCPMailLabel"); // NOI18N

        carrierContactPerson.setText(resourceMap.getString("carrierContactPerson.text")); // NOI18N
        carrierContactPerson.setName("carrierContactPerson"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(cancelButton1)
                        .addGap(18, 18, 18)
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(carrierContactPerson)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(carrierCPMailLabel)
                                        .addComponent(carrierCPNameLabel)
                                        .addComponent(carrierCPSurnameLabel)
                                        .addComponent(carrierCPPhoneLabel))
                                    .addGap(29, 29, 29)))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(carrierCPSurname, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(carrierCPPhone, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(carrierCPName, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(carrierCPMail, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(carrierNameLabel)
                                .addComponent(carrierCityLabel)
                                .addComponent(carrierAddressLabel)
                                .addComponent(carrierPhoneLabel)
                                .addComponent(carrierMailLabel)
                                .addComponent(carrierInformationLabel))
                            .addGap(33, 33, 33)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(carrierInformation)
                                .addComponent(carrierPhone, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(carrierAddress, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(carrierName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                                .addComponent(carrierMail, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(carrierCity, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)))))
                .addGap(16, 16, 16))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(carrierName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(carrierNameLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(carrierCity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(carrierCityLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(carrierAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(carrierAddressLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(carrierPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(carrierPhoneLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(carrierMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(carrierMailLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(carrierInformation, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(carrierInformationLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addComponent(carrierContactPerson)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(carrierCPName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(carrierCPNameLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(carrierCPSurname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(carrierCPSurnameLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(carrierCPPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(carrierCPPhoneLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(carrierCPMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(carrierCPMailLabel))
                .addGap(48, 48, 48)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(okButton)
                    .addComponent(cancelButton1))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
/**metoda odpowiedzialna za obsluge przycisku anuluj*/
    private void cancelButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButton1ActionPerformed
        // TODO add your handling code here:
        dispose();
}//GEN-LAST:event_cancelButton1ActionPerformed
/**metoda odpowiedzialna za obsluge przycisku ok*/
    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        carrier.nazwa = carrierName.getText();
        carrier.adres = carrierAddress.getText();
        carrier.miasto = carrierCity.getText();
        carrier.telefon = carrierPhone.getText();
        carrier.mail = carrierMail.getText();
        carrier.uwagi = carrierInformation.getText();
        carrier.ok_imie = carrierCPName.getText();
        carrier.ok_nazwisko = carrierCPSurname.getText();
        carrier.ok_telefon = carrierCPPhone.getText();
        carrier.ok_mail = carrierCPMail.getText();
        carrier.zapisz();
        if(carriersTable!=null) {
            carriersTable.zaladuj();
        }
        dispose();
}//GEN-LAST:event_okButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Przewoźnik_Kontroler dialog = new Przewoźnik_Kontroler(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton1;
    private javax.swing.JTextField carrierAddress;
    private javax.swing.JLabel carrierAddressLabel;
    private javax.swing.JTextField carrierCPMail;
    private javax.swing.JLabel carrierCPMailLabel;
    private javax.swing.JTextField carrierCPName;
    private javax.swing.JLabel carrierCPNameLabel;
    private javax.swing.JTextField carrierCPPhone;
    private javax.swing.JLabel carrierCPPhoneLabel;
    private javax.swing.JTextField carrierCPSurname;
    private javax.swing.JLabel carrierCPSurnameLabel;
    private javax.swing.JTextField carrierCity;
    private javax.swing.JLabel carrierCityLabel;
    private javax.swing.JLabel carrierContactPerson;
    private javax.swing.JTextField carrierInformation;
    private javax.swing.JLabel carrierInformationLabel;
    private javax.swing.JTextField carrierMail;
    private javax.swing.JLabel carrierMailLabel;
    private javax.swing.JTextField carrierName;
    private javax.swing.JLabel carrierNameLabel;
    private javax.swing.JTextField carrierPhone;
    private javax.swing.JLabel carrierPhoneLabel;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables
}



